#    Supsta
#    Copyright (c) 2014 Sebastian Dufner
#
#    This file is part of Supsta.
#
#    Supsta is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Supsta is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

##

module Supsta
  module Gimp

    ##
    # Class representing integer values at GIMP runtime.

    class Integer
      def initialize(scope, value)
        @app, @self = app, value
      end

      ##
      # Returns the current Scope.

      def scope
        @app
      end

      ##
      # Returns the sum of +this+ and +value+.

      def +(value)
        operator '+', value
      end

      ##
      # Returns the difference between +this+ and +value+.

      def -(value)
        operator '-', value
      end

      ##
      # Returns +this+ times +value+.

      def *(value)
        operator '*', value
      end

      ##
      # Returns +this+ divided by +value+.

      def /(value)
        operator '/', value
      end

      ##
      # Returns the variable name representing this Integer.

      def to_s
        @self.to_s
      end

    private

      def operator(op, value)
        var = @app.new_var
        scope.def var, "(* #{@self} #{value})"

        Integer.new(@app, var)
      end

    end
  end
end
